package com.risk.login.dao.mapper;

import com.risk.login.dao.po.LoginUserPo;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * @Desc
 * @Date 2018/5/23:下午11:12
 * @uthor yzMa
 * @email 2641007740@qq.com
 */
@Repository
public interface LoginUserMapper {

    @Select("<script> " +
                "SELECT * FROM `mx_user` u " +
                "WHERE u.uid = #{uid}" +
            "</script>")
    LoginUserPo selectByUid(@Param("uid") String uid);


    @Select("<script> " +
                "SELECT * FROM `mx_user` u " +
                "WHERE u.loginName = #{loginName}" +
            "</script>")
    LoginUserPo selectByLoginName(@Param("loginName") String loginName);


    @Select("<script> " +
            "SELECT * FROM `mx_user` u " +
            "WHERE u.phone = #{phone}" +
            "</script>")
    LoginUserPo selectByPhone(@Param("phone") String phone);



    /**
     * //TODO 为什么不能获取到主键？？？
     * @param loginUserPo
     * @return
     */
    @Insert({"<script>" +
            "INSERT INTO `mx_user` " +
            "(`uid`,`phone`,`loginName`,`passwd`,`nickName`,`tag`,`profilePic`,`createTime`,`updateTime`,`status`) " +
            "VALUES (#{user.uid}, #{user.phone}, #{user.loginName}, #{user.passwd}, #{user.nickName}, 0, #{user.profilePic}, NOW(), NOW(), 0)" +
            "</script>"})
    @Options(useGeneratedKeys = true,keyProperty = "#{user.id}",keyColumn = "id")
    int insert(@Param("user") LoginUserPo loginUserPo);
}
